import { useState } from 'react'

export default function App() {
  const [count, setCount] = useState(0)

  const handleClick = () => {
    // !后面的覆盖了前面的
    /* setCount(1)
    setCount(2)
    setCount(3) */
    // 类的写法
    /* this.setState(prevState => ({count: prevState.count + 1}))
    this.setState(prevState => ({count: prevState.count + 1}))
    this.setState(prevState => ({count: prevState.count + 1})) */
    // !也能拿到累计后的结果
    setCount((prevState) => prevState + 1)
    setCount((prevState) => prevState + 2)
    setCount((prevState) => prevState + 3)
    console.log(count) // !0，setCount 修改数据的表现也是异步的
  }
  return (
    <div>
      <h3>{count}</h3>
      <button onClick={handleClick}>+1</button>
    </div>
  )
}
